package gui;

import javax.swing.*;
import javax.swing.*;

import calculation.MatrixLibrary;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import common.*;

public class DialogDeleteFile extends JFrame {
	private MyLabel label = new MyLabel(new ImageIcon("./image/dialogDeleteMatrix.png"));
	// private MyTextField text1 = new MyTextField();
	// private MyTextField text2 = new MyTextField();
	String check = "Are you sure you want to delete matrix: ";
	static String matrixName = "Matrix A";
	private JLabel warning = new JLabel(check);
	static JLabel name = new JLabel(matrixName);
	private MyButton ok = new MyButton(new ImageIcon("./image/ok.png"));
	private MyButton cancel = new MyButton(new ImageIcon("./image/cancel.png"));
	FrameMain f = null;
	public static String targetName = null;

	// public DialogDeleteFile(String str){
	// this.targetName = str;
	// }
	public DialogDeleteFile(FrameMain MainFrame) {
		f = MainFrame;
		setSize(451, 220);
		setResizable(false);

		label.setBounds(0, 0, 451, 220);
		// label.setLayout(new BoxLayout(label,BoxLayout.Y_AXIS));
		warning.setBounds(90, 65, 451, 25);
		name.setBounds(190, 85, 451, 25);
		ok.setBounds(30, 120, 154, 52);
		cancel.setBounds(255, 120, 154, 52);
		// text2.setBounds(x, y, width, height);
		label.add(warning);
		label.add(name);
		label.add(ok);
		label.add(cancel);
		this.add(label);
		MouseListener listenerOk = new MouseListener() {
			public void mouseEntered(MouseEvent e) {
			}

			public void mouseClicked(MouseEvent arg0) {

				f.getFileHandler().deleteFile(targetName);

				f.getInputHandler().loadMatricesFromLibraryDirectory();
				String[] nameList = (String[]) MatrixLibrary.getNameList().toArray(new String[0]);
				f.getPanelDisplayMatrixList().updateMyLayout(nameList);
				f.getPanelCalculationBar().setMatrixNameList(nameList);

				f.getDialogDeleteFile().setVisible(false);

			}

			public void mouseExited(MouseEvent arg0) {
			}

			public void mousePressed(MouseEvent arg0) {
			}

			public void mouseReleased(MouseEvent arg0) {
			}
		};
		ok.addMouseListener(listenerOk);
		MouseListener listenerCancel = new MouseListener() {
			public void mouseEntered(MouseEvent e) {
			}

			public void mouseClicked(MouseEvent arg0) {
				f.getDialogDeleteFile().setVisible(false);
			}

			public void mouseExited(MouseEvent arg0) {
			}

			public void mousePressed(MouseEvent arg0) {
			}

			public void mouseReleased(MouseEvent arg0) {
			}
		};
		cancel.addMouseListener(listenerCancel);
	}

	public static void setTarget(String target) {
		targetName = target;
		name.setText(target);
	}

}
